package org.shopen.ai.puremvc.controller.startup
{
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	import org.puremvc.as3.utilities.statemachine.FSMInjector;
	import org.shopen.ai.puremvc.ApplicationConstants;

	public class InjectFsmCommand extends SimpleCommand
	{
		override public function execute(notification:INotification):void
		{
			var fsm:XML = 
			<fsm initial={ApplicationConstants.STATE_INTRO}>
			   <state name={ApplicationConstants.STATE_INTRO}>
			       <transition action={ApplicationConstants.ACTION_SELECT_PROJECT} target={ApplicationConstants.STATE_PROJECT}/>
			   </state>
			   <state name={ApplicationConstants.STATE_PROJECT}>
			   		<transition action={ApplicationConstants.ACTION_NEXT} target={ApplicationConstants.STATE_PROJECT_PREVIEW}/>
			   </state>
			   <state name={ApplicationConstants.STATE_PROJECT_PREVIEW}>
			       <transition action={ApplicationConstants.ACTION_SELECT_PROJECT} target={ApplicationConstants.STATE_PROJECT}/>
			       <transition action={ApplicationConstants.ACTION_NEXT} target={ApplicationConstants.STATE_PROJECT_SETUP}/>
			   </state>
			    <state name={ApplicationConstants.STATE_PROJECT_SETUP}>
			    	<transition action={ApplicationConstants.ACTION_SELECT_PROJECT} target={ApplicationConstants.STATE_PROJECT}/>
			        <transition action={ApplicationConstants.ACTION_PREV} target={ApplicationConstants.STATE_PROJECT_PREVIEW}/>
			        <transition action={ApplicationConstants.ACTION_NEXT} target={ApplicationConstants.STATE_PROJECT_SEARCHING}/>
			  </state>
			   <state name={ApplicationConstants.STATE_PROJECT_SEARCHING} entering={ApplicationConstants.ENTERING_PROJECT_SEARCHING}>
			       	<transition action={ApplicationConstants.ACTION_NEXT} target={ApplicationConstants.STATE_PROJECT_STATISTIC}/>
			       	<transition action={ApplicationConstants.ACTION_ABORT} target={ApplicationConstants.STATE_PROJECT_SEARCH_STOPPED}/>
			   </state>
			   <state name={ApplicationConstants.STATE_PROJECT_SEARCH_STOPPED}>
			    	<transition action={ApplicationConstants.ACTION_SELECT_PROJECT} target={ApplicationConstants.STATE_PROJECT}/>
			       	<transition action={ApplicationConstants.ACTION_PREV} target={ApplicationConstants.STATE_PROJECT_SETUP}/>
			   </state>
			   <state name={ApplicationConstants.STATE_PROJECT_STATISTIC}>
			    	<transition action={ApplicationConstants.ACTION_SELECT_PROJECT} target={ApplicationConstants.STATE_PROJECT}/>
			       	<transition action={ApplicationConstants.ACTION_TRY_AGAIN} target={ApplicationConstants.STATE_PROJECT_SETUP}/>
			       	<transition action={ApplicationConstants.ACTION_PREV} target={ApplicationConstants.STATE_PROJECT_SEARCH_STOPPED}/>
			   </state>
			</fsm>;
			
			// Create and inject the StateMachine 
			var injector : FSMInjector = new FSMInjector(fsm);
			injector.inject();
		}
	}
}